package com.cww.study.mybatis;


import com.github.pagehelper.Page;

import java.io.Serializable;
import java.util.List;

/**
 * @program: myes
 * @description: 添加分页依赖, pagemethod开启分页, list 不可以更改
 * @author: 陈英俊
 * @create: 2021-09-16 14:22
 */
public class PageResultBean<T> implements Serializable {
    private static final long serialVersionUID = -6477868212171605239L;
    private Long total;
    private List<T> rows;
    private Integer pageNum;
    private Integer pageSize;
    private Integer pages;

    public PageResultBean(List<T> rows) {
        this.init(rows);
    }

    public PageResultBean() {
    }

    private void init(List<T> rows) {
        if (rows instanceof Page) {
            Page<T> page = (Page) rows;
            this.total = page.getTotal();
            this.rows = page.getResult();
            this.pageNum = page.getPageNum();
            this.pageSize = page.getPageSize();
            this.pages = page.getPages();
        }

    }

    public Long getTotal() {
        return this.total;
    }

    public void setTotal(Long total) {
        this.total = total;
    }

    public List<T> getRows() {
        return this.rows;
    }

    public void setRows(List<T> rows) {
        this.rows = rows;
    }

    public Integer getPageNum() {
        return this.pageNum;
    }

    public void setPageNum(Integer pageNum) {
        this.pageNum = pageNum;
    }

    public Integer getPageSize() {
        return this.pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getPages() {
        return this.pages;
    }

    public void setPages(Integer pages) {
        this.pages = pages;
    }
}
